import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:namewava/pages/launch/widgets/jc_agree_text.dart';
import 'package:namewava/pages/launch/widgets/jc_login_btn.dart';
import 'package:namewava/pages/launch/widgets/jc_login_widget.dart';
import 'package:namewava/utils/jc_image_path.dart';
import 'package:namewava/utils/jc_text_style.dart';
import 'package:app_tracking_transparency/app_tracking_transparency.dart';

class JcLoginPage extends StatefulWidget {
  const JcLoginPage({super.key});

  @override
  State<JcLoginPage> createState() => _JcLoginPageState();
}

class _JcLoginPageState extends State<JcLoginPage> {
  RxBool isSelect = false.obs;
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      // _t();
      _initAppTrackingTransparency();
    });
  }

  _initAppTrackingTransparency() async {
    final TrackingStatus status =
        await AppTrackingTransparency.trackingAuthorizationStatus;
    if (status == TrackingStatus.notDetermined) {
      final TrackingStatus status =
          await AppTrackingTransparency.requestTrackingAuthorization();
      print("status: $status");
    }
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        onWillPop: () async {
          return false;
        },
        child: Container(
          color: const Color(0xFF1445CD),
          child: Column(
            children: [
              JcLoginWidget(
                top: 88.h,
              ),
              Text(
                'CardForge',
                style: JcTextStyle.poetsenOneRegularTextStyle(25, Colors.white),
              ),
              Obx(() {
                return JcLoginBtn(
                  butnTitle: 'Get in',
                  top: 115.h,
                  imageIcon: JcImagePath.jcWavaRight,
                  loginType: 0,
                  isArgger: isSelect.value,
                  argeeEvents: () {
                    isSelect.value = true;
                  },
                );
              }),
              Obx(() {
                return JcLoginBtn(
                  butnTitle: 'Sign in with Apple',
                  top: 25.h,
                  imageIcon: JcImagePath.jcWavaA,
                  loginType: 1,
                  isArgger: isSelect.value,
                  argeeEvents: () {
                    isSelect.value = true;
                  },
                );
              }),
              _agreeWidget()
            ],
          ),
        ));
  }

  _agreeWidget() {
    return Container(
      margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 25.h),
      padding: EdgeInsets.only(
        left: 15.w,
        right: 17.w,
      ),
      height: 76.h,
      // decoration: BoxDecoration(
      //     color: const Color.fromRGBO(151, 180, 245, 1),
      //     borderRadius: BorderRadius.circular(20.r)),
      decoration: const BoxDecoration(
          image: DecorationImage(
              image: AssetImage(JcImagePath.jcWavaXieyiBg), fit: BoxFit.fill)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          GestureDetector(
            child: Obx(() {
              if (isSelect.value) {
                return Image.asset(JcImagePath.jcWavaStatuesSelect);
              } else {
                return Image.asset(JcImagePath.jcWavaStatuesNormal);
              }
            }),
            onTap: () {
              isSelect.value = !isSelect.value;
            },
          ),
          SizedBox(
            width: 5.w,
          ),
          const Expanded(child: JcAgreeText())
        ],
      ),
    );
  }
}
